# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: getzze <getzze at gmail dot com>
pkgbase=python-tensorflow-serving-api
pkgname=("${pkgbase}" "${pkgbase}"-gpu)
_pkgname=tensorflow_serving_api
pkgver=2.14.0
pkgrel=1
pkgdesc="Serving system for machine learning models, designed for production environments"
arch=(any)
url="https://www.tensorflow.org/serving/"
license=('Apache')
depends=('python' 'python-grpcio' 'python-tensorflow' 'python-protobuf')
makedepends=('bazel' 'git' 'python-build' 'python-installer' 'python-wheel')
source=("$pkgname-$pkgver.tar.gz::https://github.com/tensorflow/serving/archive/${pkgver}.tar.gz")
b2sums=('a479b7f0ac3ebfb2a910bfc796884bdeb1d74499f11751e31fd293815289b28a9f0a93e1a9db64d7890398eb5e88716988f582bf1c9c03a7773ba3bff81f4ab9')

build() {
  cd serving-*
  bazel build -c opt tensorflow_serving/tools/pip_package:build_pip_package
  sed -i "s|bazel-genfiles/|bazel-out/k8-opt/bin/|g" tensorflow_serving/tools/pip_package/build_pip_package.sh
  mkdir "${srcdir}/dist"
  bazel-bin/tensorflow_serving/tools/pip_package/build_pip_package "${srcdir}/dist"
  ls -lah "${srcdir}/dist"
}

package_python-tensorflow-serving-api() {
  cd serving-*
  python -m installer --destdir="${pkgdir}" "${srcdir}/dist/${_pkgname}"-*.whl
  install -Dm644 LICENSE "${pkgdir}"/usr/share/licenses/"${pkgname}"/LICENSE
}

package_python-tensorflow-serving-api-gpu() {
  pkgdesc+=" (with GPU support)"
  provides=(python-tensorflow-serving-api)
  conflicts=(python-tensorflow-serving-api)
  cd serving-*
  python -m installer --destdir="${pkgdir}" "${srcdir}/dist/${_pkgname}"_gpu-*.whl
  install -Dm644 LICENSE "${pkgdir}"/usr/share/licenses/"${pkgname}"/LICENSE
}
